import React from 'react';
import { Navigate } from 'react-router-dom';

interface AuthGuardProps {
    children: React.ReactNode;
}

const AuthGuard: React.FC<AuthGuardProps> = ({ children }) => {
    // 检查是否有 token
    const token = localStorage.getItem('token');

    if (!token) {
        // 没有 token，跳转到登录页
        return <Navigate to="/login" replace />;
    }

    // 有 token，渲染子组件
    return <>{children}</>;
};

export default AuthGuard; 